//
//  FEGuideViewController.m
//  familyeducation
//
//  Created by 聂志康 on 2017/3/24.
//  Copyright © 2017年 shangdingkeji. All rights reserved.
//

#import "FEGuideViewController.h"
#import "FEGuideCell.h"

@interface FEGuideViewController ()
//{
//    NSInteger currentPage;
//}
@property (nonatomic, strong) NSArray<UIImage *> *iphone6imagesArr;
@property (nonatomic, strong) NSArray<UIImage *> *iphone6PimagesArr;
@property (nonatomic, strong) NSArray<UIImage *> *iphoneXimagesArr;
//@property (nonatomic, weak) UIPageControl *pageControl;
@end

@implementation FEGuideViewController

- (instancetype)init {
    // 1.流水布局
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 1.2 设置cell的大小
    flowLayout.itemSize = [UIScreen mainScreen].bounds.size;
    // 1.3 设置滚动方向 水平滚动
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    // 1.4 设置间距
    flowLayout.minimumLineSpacing = 0;
    return [super initWithCollectionViewLayout:flowLayout];
}

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    // 0.设置背景颜色
    self.collectionView.backgroundColor = [UIColor whiteColor];
    // 1.设置分页效果
    self.collectionView.pagingEnabled = YES;
    // 2.关闭弹簧效果
    self.collectionView.bounces = NO;
    // 3.关闭底部的滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    // 4.注册cell
    [self.collectionView registerClass:[FEGuideCell class] forCellWithReuseIdentifier:reuseIdentifier];
//    // 5.添加pageControl
//    UIPageControl *pageControl = [[UIPageControl alloc] init];
//    pageControl.userInteractionEnabled = NO;
//    pageControl.numberOfPages = self.imgsArr.count;
//    pageControl.pageIndicatorTintColor = hexColor(f39800);
//    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
//    self.pageControl = pageControl;
//    [self.view addSubview:pageControl];
//    //----------------------华丽的分割线-----------------------//
//    //weakSelf防止强引用
//    __weak typeof(self) weakSelf = self;
//    [pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(weakSelf.view.centerX);
//        make.bottom.equalTo(weakSelf.view.bottom);
//    }];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//    currentPage = self.collectionView.contentOffset.x/ScreenW;
//    [self.pageControl setCurrentPage:currentPage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.iphone6imagesArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FEGuideCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    // 1.设置背景图片
    if (kIPHONEX) {
        cell.backgroundView = [[UIImageView alloc] initWithImage:self.iphoneXimagesArr[indexPath.row]];
    } else if (kIPHONE6P) {
        cell.backgroundView = [[UIImageView alloc] initWithImage:self.iphone6PimagesArr[indexPath.row]];
    } else {
        cell.backgroundView = [[UIImageView alloc] initWithImage:self.iphone6imagesArr[indexPath.row]];
    }
    // 如果是最后一个cell，显示按钮，否则，隐藏
    if (indexPath.item == self.iphone6imagesArr.count - 1) {
        cell.experienceBtn.hidden = NO;
    } else {
        cell.experienceBtn.hidden = YES;
    }
    return cell;
}

- (void)dealloc {
    NSLog(@"新特性 --- oVer");
}

#pragma mark - 懒加载
- (NSArray *)iphone6imagesArr {
    if (_iphone6imagesArr == nil) {
        _iphone6imagesArr = @[
                     [UIImage imageNamed:@"guide1Background_iPhone6"],
                     [UIImage imageNamed:@"guide2Background_iPhone6"],
                     [UIImage imageNamed:@"guide3Background_iPhone6"]
                     ];
    }
    return _iphone6imagesArr;
}

- (NSArray *)iphone6PimagesArr {
    if (_iphone6PimagesArr == nil) {
        _iphone6PimagesArr = @[
                              [UIImage imageNamed:@"guide1Background_iPhone6P"],
                              [UIImage imageNamed:@"guide2Background_iPhone6P"],
                              [UIImage imageNamed:@"guide3Background_iPhone6P"]
                              ];
    }
    return _iphone6PimagesArr;
}

- (NSArray *)iphoneXimagesArr {
    if (_iphoneXimagesArr == nil) {
        _iphoneXimagesArr = @[
                              [UIImage imageNamed:@"guide1Background_iPhoneX"],
                              [UIImage imageNamed:@"guide2Background_iPhoneX"],
                              [UIImage imageNamed:@"guide3Background_iPhoneX"]
                              ];
    }
    return _iphoneXimagesArr;
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}



@end
